/* 
 *   Date       Developer   Description
 *   
 *
 *   Classname:  zzz.test.component.mina2.test01.server.Test01Server
 * 
 *   Date:   2014-3-16
 * 
 *   The source code contained in this listing is proprietary to
 *   HLJ POST YITONG INFO-NET CO.,LTD.
 * 
 *   Unauthorized copying, adaptation, distribution, use, or display
 *   is strictly prohibited.
 *   This software is Copyright 2014 HLJ POST YITONG INFO-NET CO.,LTD.
 */
package com.titan.demo.camel.sample.component.mina2.test01.server;

import java.net.InetSocketAddress;

import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSessionConfig;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 *
 *
 * @author Administrator
 *
 */
public class Test01Server {
    private static Logger logger = LoggerFactory.getLogger(Test01Server.class);
    private static int PORT = 3005;
    public static void main(String[] args) {
        IoAcceptor acceptor = null;
        try {
            // 创建一个非阻塞的server端的Socket
            acceptor = new NioSocketAcceptor();
            // 直接发送对象
            acceptor.getFilterChain().addLast(
                    "codec",
                    new ProtocolCodecFilter(
                            new ObjectSerializationCodecFactory()));

            // 获得IoSessionConfig对象
            IoSessionConfig cfg = acceptor.getSessionConfig();
            // 读写通道10秒内无操作进入空闲状态
            cfg.setIdleTime(IdleStatus.BOTH_IDLE, 100);

            // 绑定逻辑处理器
            acceptor.setHandler(new Test01ServerHandler());
            // 绑定端口
            acceptor.bind(new InetSocketAddress(PORT));
            logger.info("服务端启动成功...     端口号为：" + PORT);
        } catch (Exception e) {
            logger.error("服务端启动异常....", e);
            e.printStackTrace();
        }
    }
}

